# 4. 插入数据
import sqlite3
from mysql.create_db import cursor, conn

try:
    cursor.execute("INSERT INTO users (name, age, email) VALUES (?, ?, ?)",
                   ("Alice", 25, "alice@example.com"))
    cursor.execute("INSERT INTO users (name, age, email) VALUES (?, ?, ?)",
                   ("Bob", 30, "bob@example.com"))
    # 提交事务（插入/更新/删除需要提交）
    conn.commit()
    print("数据插入成功")
except sqlite3.IntegrityError:
    print("邮箱已存在，插入失败")
except sqlite3.Error as e:
    print(f"插入数据失败：{e}")
    # 出错时回滚事务
    conn.rollback()